import axios from 'axios'
import {serverUrl} from '@/utils/common'

const request = axios.create({
    baseURL: serverUrl,
    timeout: 10000
})

request.interceptors.request.use(function (config) {
  if(sessionStorage.getItem('user')){
    let user = JSON.parse(sessionStorage.getItem('user'))
    config.headers.Authorization = 'Bearer '+ user.token;
  }
 
  return config;
}, function (error) {
 
  return Promise.reject(error);
});

request.interceptors.response.use(function (response) {
  return response.data;
}, function (error) {
  return Promise.reject(error);
});
export default request;